package org.skavookie

/**
 * Created by IntelliJ IDEA.
 * User: joshua
 * Date: 9/21/11
 * Time: 2:37 PM
 * To change this template use File | Settings | File Templates.
 */

package object linalg {

//  implicit def vector2vec(v: Vector[Double]): Vec = Vec(v: _*)
//  implicit def vec2vector(v: Vec): Vector[Double] = Vector(v.vector: _*)

  /** The 'Real' type */
  type Real = Double

  implicit def seq2vec(s: Seq[Double]): Vec = Vec(s: _*)
  implicit def vec2seq(v: Vec): Seq[Double] = v.vector
  implicit def seqSeq2mat(s: Seq[Seq[Double]]): Matrix = Matrix(s: _*)
  implicit def mat2seqSeq(m: Matrix): Seq[Seq[Double]] = m.matrix

//  def dot[A](a: Seq[A], b: Seq[A])(implicit num: Numeric[A]): A =
//    (a zip b) map { case (a1,a2) => num.times(a1,a2) } sum

  case class Vec3Ops(x: Double, y: Double, z: Double) {
//    def *(v: Vec3): Double = x*v.x + y*v.y + z*v.z
//    def *(s: Double): Vec3 = Vec3(x*s, y*s, z*s)
//    def +(v: Vec3): Vec3 = Vec3(x+v.x, y+v.y, z+v.z)
//    def negate: Vec3 = Vec3(-x, -y, -z)
//    def -(v: Vec3): Vec3 = this + v.negate
//    lazy val norm: Double = math.sqrt(this*this)
    def cross(v: Vec3Ops): Vector[Double] = Vector(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x)
  }
  implicit def vec3ops2vector(v: Vec3Ops): Vector[Double] = Vector(v.x, v.y, v.z)
  implicit def vector2vec3ops(v: Vector[Double]): Vec3Ops = v match {
    case Vector(x, y, z) => Vec3Ops(x,y,z)
    case _ => throw new IllegalArgumentException("opps!")
  }
}